
import api from '../../../api/index'
import { userInfoStore } from '../../../store/userInfo'

const app = getApp()

Page({

  data: {
    userLevel: 0,

    constructionAddress:'',

    steps: [{
      id: 1,
      name: '出货审核',
    }, {
      id: 2,
      name: '已出货',
    }, {
      id: 3,
      name: '到货验货',
    }, {
      id: 4,
      name: '室内机吊装',
    }, {
      id: 5,
      name: '空调或新风管路连接',
    }, {
      id: 6,
      name: '冷凝水排水测试',
    }, {
      id: 7,
      name: '管路打压测试',
    }, {
      id: 8,
      name: '抽真空、加氟、连外机',
    }, {
      id: 9,
      name: '出/回风口安装、调试',
    }, {
      id: 10,
      name: '空调验收报告',
    }],

    maskHidden:false,
    playMp4Url:null,
  },
  
  onLoad: function (options) {
    this.setData({ userLevel: userInfoStore.userInfo.level })
    let self = this
    // openId: 'ofhiR4vgDWazdlvVd-gf0IIrtX_c',
    api.getConstruction({
      openId: userInfoStore.userInfo.openId,
      constructionId: options.id
    }).then(res => {
      for (var i = 0; i < res.result.steps.length; i++) {
          for(var j=0; j<self.data.steps.length; j++){
            if (self.data.steps[j].id == res.result.steps[i].step){
              self.data.steps[j].detail = res.result.steps[i];
              break;
            }
          }
      }

      self.setData({ 
        constructionAddress: res.result.address,
        steps: self.data.steps
      })
    })

  },

  showBigImage: function(e){
    let item = e.currentTarget.dataset.item;
    if (item.suffix=='video'){
      this.setData({
        maskHidden: true,
        playMp4Url: item.url
      })
    }else{
      wx.previewImage({
        urls: [item.url],
      })
    }
  },

  bindVideoEnded: function () {
    this.setData({
      maskHidden: false,
      playMp4Url: null
    })
  },

  closeVideo: function(){
    var videoContext = wx.createVideoContext('videoBox');
    videoContext.seek(0);
    videoContext.pause();
    this.setData({
      maskHidden: false,
      playMp4Url: null
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    getApp().share();
  }
})